package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.pojo.AssociatedBusinessAfterSavePojo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessproduct.pojo.dto.BusinessProductListDTO;
import com.xbongbong.pro.businessproduct.pojo.vo.RefundAmountVO;
import com.xbongbong.pro.detailtab.dto.ChangeDocumentStatusSaveDTO;
import com.xbongbong.pro.detailtab.vo.ChangeDocumentStatusSaveVO;
import com.xbongbong.pro.detailtab.vo.ProductSummaryVO;
import com.xbongbong.pro.formdata.pojo.AfterSavePojo;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.product.pojo.ProductSavePojo;
import com.xbongbong.pro.product.pojo.dto.PagingProductDTO;
import com.xbongbong.pro.product.pojo.vo.PagingProductVO;
import com.xbongbong.pro.refund.pojo.dto.RefundDeleteBatchDTO;
import com.xbongbong.pro.refund.pojo.dto.RefundEditAttrUpdateDTO;
import com.xbongbong.pro.refund.pojo.dto.RefundUpdateBatchDTO;
import com.xbongbong.pro.refund.pojo.dto.RefundUpdateByBusinessRuleDTO;
import com.xbongbong.pro.refund.pojo.vo.RefundDeleteBatchVO;
import com.xbongbong.pro.refund.pojo.vo.RefundEditAttrUpdateVO;
import com.xbongbong.pro.refund.pojo.vo.RefundUpdateBatchVO;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;

import java.util.List;
import java.util.Map;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/18
 * @since v1.0
 */
public interface RefundService {
    /**
     * 判断进销存是否开启
     *
     * @param corpid 公司Id
     * @return boolean
     * @author youli.chen
     * @date 2019/3/7 8:50
     * @since v1.0
     * @throws XbbException 业务异常
     */
    boolean ifJXCOpen(String corpid) throws XbbException;
    /**
     * 保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/18
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * 保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @param associatedBusinessAfterSavePojo 关联新建发票、回款单相关信息
     * @throws XbbException 业务异常
     * @author feng.zheng
     */
    AfterSavePojo afterSave(SaasFormSaveDTO saasFormSaveDTO, AssociatedBusinessAfterSavePojo associatedBusinessAfterSavePojo) throws XbbException;



    /**
     * 关联新建格式化解释
     *
     * @param handlerExplainInLinkItemDTO 入参
     * @throws XbbException 异常
     */
    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;

    /**
     * 新建格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     */
    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 格式化移动端列表页
     *
     * @param formDataListDTO 用户
     * @param esEntities      业务实体集合
     * @param totalCount      总数
     * @return ListAppVO
     * @throws XbbException
     * @author long.rao
     * @date 2019-03-11 13:50
     */
    ListAppVO formatRefundAppList(FormDataListDTO formDataListDTO, List<PaasFormDataEntityExt> esEntities, Integer totalCount) throws XbbException;

    /**
     * 格式化产品，显示给前端
     *
     * @param dataList            实体数据
     * @param saasAnalysisDataDTO 数据解析DTO
     * @throws XbbException
     * @author long.rao
     * @date 2019-03-02 16:35
     */
    void formatProduct4Show(JSONObject dataList, SaasAnalysisDataDTO saasAnalysisDataDTO) throws XbbException;

    /**
     * 获取退货退款关联产品
     *
     * @param businessProductListDTO
     * @param dataList
     * @return
     * @throws
     * @author 有利
     * @date: 2019-04-09 16:42
     * @version v1.0
     * @since v1.0
     */
//    BusinessProductListVO getRefundProductList(BusinessProductListDTO businessProductListDTO, JSONObject dataList, boolean refund) throws XbbException;

    /**
     * 批量删除退货退款
     *
     * @param refundDeleteBatchDTO
     * @return RefundDeleteBatchVO
     * @throws XbbException 业务异常
     * @author youli.chen
     * @date 2019/3/13 14:02
     */
    RefundDeleteBatchVO deleteBatch(RefundDeleteBatchDTO refundDeleteBatchDTO) throws XbbException;

    /**
     * 之前是获取产品金额，获取退货退款的退货金额（特殊处理）
     * @param businessProductListDTO
     * @return
     */
    RefundAmountVO getRefundAmount(BusinessProductListDTO businessProductListDTO) throws XbbException;

    /**
     * 批量更新
     * @author 吴峰
     * @date 2019/3/5 14:14
     * @param refundUpdateBatchDTO
     * @return com.xbongbong.pro.refund.pojo.vo.RefundUpdateBatchVO
     * @throws XbbException 业务异常
     */
    RefundUpdateBatchVO updateBatch(RefundUpdateBatchDTO refundUpdateBatchDTO) throws XbbException;

    RefundUpdateBatchVO updateBatchImmediately(RefundUpdateBatchDTO refundUpdateBatchDTO) throws XbbException;

    /**
     * 格式化导出excelvalue
     *
     * @param importFormDataDTO 入参
     * @param titlePojoList 标题
     * @param rowGroupPojo 组
     * @param fieldAttrList 解释
     * @return
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 格式化导出数据
     *
     * @param paasFormDataESList 数据
     * @param formDataListDTO 入参
     * @param fieldAttrList 解释
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 批量编辑
     * @author 陈有利
     * @date 2019/3/7 16:45
     * @param refundEditAttrUpdateDTO
     * @return com.xbongbong.pro.suppliercontact.pojo.vo.RefundEditAttrUpdateVO
     * @throws XbbException 业务异常
     */
    RefundEditAttrUpdateVO batchEditAttr(RefundEditAttrUpdateDTO refundEditAttrUpdateDTO) throws XbbException;

    Double getRefundReturnAmount(String corpid, Long contractId) throws XbbException;

    /**
     * 入库单保存后判断是否出库完毕
     * @param instockId
     * @param refId
     * @param corpid
     * @param productSavePojoList
     * @return
     */
    boolean judgeRefundAllInBound(Long instockId, Long refId, String corpid, List<ProductSavePojo> productSavePojoList) throws XbbException;

    /**
     * 汇总机会产品信息（详情页，几种产品几件）
     *
     * @param businessProductListDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-28 10:23
     */
    ProductSummaryVO summaryProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;

    /**
     *
     * @author 吴峰
     * @date 2019/8/16 21:36
     * @param refundUpdateByBusinessRuleDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void updateBatchByBusinessRule(RefundUpdateByBusinessRuleDTO refundUpdateByBusinessRuleDTO) throws XbbException;


    /**
     * 更新退货退款中的发票ID
     * @param refundId 退货退款ID
     * @param paasFormDataEntity 发票实体
     * @param saasFormSaveDTO 入参
     * @throws XbbException error
     * @author zhouwq
     * @date 2019/12/19 11:17
     */
    void updateRefundInvoiceId(Long refundId, PaasFormDataEntity paasFormDataEntity, SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    /**
     * 删除回款单更新退货退款中的合计退款金额
     * @param corpid 公司ID
     * @param delIdList 要删除的回款单id集合（不包含子回款单）
     * @param sheetIdToAmount 回款单id-回款金额（预收款核销要读取核销金额）
     * @author zhouwq
     * @date 2019/12/20 14:50
     */
    void updateRefund4Del(String corpid, List<Long> delIdList, Map<Long, Double> sheetIdToAmount) throws XbbException;

    void dataConsistencyUpdate(String corpid, Long dataId, String value, String attr, String linkAttr) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    PagingProductVO getPagingProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    /**
     * Description: 获取退货退款名称集合
     * @param handoverIdSet
     * @param corpid
     * @author 刘阳
     * @date 2020/1/8 2:41 PM
     * @since v1.0
     */
    Map<Long, String> getRefundNameMap(List<Long> handoverIdSet, String corpid) throws XbbException;

    void formatBatchExplain(List<FieldAttrEntity> fieldAttrEntityList, String enable);

    /**
     * 跟新退货退款开启关闭状态
     * @param changeDocumentStatusSaveDTO
     * @return
     */
    ChangeDocumentStatusSaveVO changeDocumentStatus(ChangeDocumentStatusSaveDTO changeDocumentStatusSaveDTO) throws XbbException;

    /**
     * 批量增删标签
     * @param addLabelDTO
     * @param addBatchList
     * @throws XbbException
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO, AssociatedBusinessAfterSavePojo associatedBusinessAfterSavePojo) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO, AssociatedBusinessAfterSavePojo refundAfterSavePojo) throws XbbException;
}
